using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for bzContact
/// </summary>
public class bzContact
{
	private dbConnection _DB = null;
    private string _TableName = "bzContact";
    private string _IDType = "_INT";
    private string _IDCol = "ContactID";
    private string _IDColParent = "";
    private string _TableChild = "";
    public struct Enable
    {
        private static int _Enabled = 1;
        public static int Enabled { get { return _Enabled; } }

        private static int _Disabled = 1;
        public static int Disabled { get { return _Disabled; } }
    }
    public bzContact()
    {
        _DB = new dbConnection();
    }
    public DataTable getTable(string Key, string Enabled, string Page, string Limit)
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled", Enabled);       
        p[2] = new SqlParameter("@Page", Page);
        p[3] = new SqlParameter("@Limit", Limit);
        return _DB.getDataTable(_TableName + "_search", p);

    }
    public long getTotal(string Key, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[2];
        p[0] = new SqlParameter("@Key", "%" + Key + "%");
        p[1] = new SqlParameter("@Enabled", Enabled);
        return _DB.getTotalTable(_TableName + "_getTotal", p);
    }
    public DataTable getRecord(string ID, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@TableName", _TableName);
        p[1] = new SqlParameter("@IDCol", _IDCol);
        p[2] = new SqlParameter("@IDValue", ID);
        p[3] = new SqlParameter("@Enabled", Enabled);
        return _DB.getDataTable("bz_getRecord" + _IDType, p);
    } 
    public int deleteRecord(string[] ID)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@TableChild", _TableChild);
            p[2] = new SqlParameter("@IDCol", _IDCol);
            p[3] = new SqlParameter("@IDValue", str);
            count += _DB.updateData("bz_deleteRecord" + _IDType, p);
        }
        return count;
    }
    public int activeRecord(string[] ID, string Enabled)
    {
        int count = 0;
        foreach (string str in ID)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@TableName", _TableName);
            p[1] = new SqlParameter("@IDCol", _IDCol);
            p[2] = new SqlParameter("@IDValue", str);
            p[3] = new SqlParameter("@Enabled", Enabled);
            count += _DB.updateData("bz_activeRecord" + _IDType, p);
        }
        return count;
    }

    public int insertRecord(string NameFull, string Company, string Address, string Phone, string Fax, string Email, string Subject, string Content, string Enabled)
    {
        SqlParameter[] p = new SqlParameter[9];
        p[0] = new SqlParameter("@NameFull", NameFull);
        p[1] = new SqlParameter("@Company", Company);
        p[2] = new SqlParameter("@Address", Address);
        p[3] = new SqlParameter("@Phone", Phone);
        p[4] = new SqlParameter("@Fax", Fax);
        p[5] = new SqlParameter("@Email", Email);
        p[6] = new SqlParameter("@Subject", Subject);
        p[7] = new SqlParameter("@Content", Content);
        p[8] = new SqlParameter("@Enabled", Enabled);

        return _DB.updateData(_TableName + "_insert", p);
    }
    public int updateRecord(string ID,  string Enabled)
    {
        SqlParameter[] p = new SqlParameter[2];
        p[0] = new SqlParameter("@ID", ID);       
        p[1] = new SqlParameter("@Enabled", Enabled);        
        return _DB.updateData(_TableName + "_update", p);
    }    
}
